﻿using IMark.DAO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace IMark.Admin.Account
{
    public partial class Index : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Utils.CheckAuthentication("SAdmin"))
            {
                if (!IsPostBack)
                {
                    LoadData();
                }
            }
            else
            {
                Response.Redirect("~/Admin/Account/Home.aspx");
            }
        }
        private void LoadData()
        {
            info.InnerHtml = string.Empty;
            if ((string)Session["Info"] != "")
            {
                info.InnerHtml = (string)Session["Info"];
                Session["Info"] = "";
            }

            List<NGUOI_DUNG> dataAccount = NguoiDungModels.GetAll();
            if (dataAccount.Count > 0)
            {
                StringBuilder str = new StringBuilder();
                foreach (var item in dataAccount)
                {
                    //string urlUpdate = ResolveClientUrl("~/Admin/Account/Update.aspx?ID=" + item.ID);
                    string urlDelete = ResolveClientUrl("~/Admin/Account/Delete.aspx?ID=" + item.ID);
                    string role = "Admin";
                    if(item.IDLoaiNguoiDung == 1)
                        role = "Super Admin";
                    str.Append("<tr class=\"odd gradePhone\">");
                    str.Append("<td>" + item.TenDangNhap + "</td>");
                    str.Append("<td>" + item.HoTen + "</td>");
                    str.Append("<td>" + item.Email + "</td>");
                    str.Append("<td>" + item.DiaChi + "</td>");
                    str.Append("<td>" + role + "</td>");
                    
                    str.Append("<td class=\"tbitem-action text-center\">");
                    //str.Append("<a href=\"" + urlUpdate + "\" class=\"btn btn-primary btn-circle\" title=\"Cập nhật\">");
                    //str.Append("<i class=\"fa fa-edit\"></i>");
                    //str.Append("</a>");                    
                    str.Append("<button data-toggle=\"modal\" data-target=\"#modalDeleteItems\" onclick=\"return DeleteItems('" + urlDelete + "')\" class=\"btn btn-danger btn-circle\" type=\"button\" title=\"Xóa\">");
                    str.Append("<i class=\"fa fa-times\"></i>");
                    str.Append("</button>");
                    str.Append("</td>");
                    str.Append("</tr>");
                }
                lstAccount.InnerHtml = str.ToString();
            }
        }

        protected void btnAdd_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/Admin/Account/Add.aspx");
        }
    }
}